package lc2

import (
	"reflect"
	"testing"
)

func getNodeList(nums []int) *ListNode {
	result := &ListNode{}
	p := result
	for _, num := range nums {
		p.Next = &ListNode{num, nil}
		p = p.Next
	}
	return result.Next
}

func getNums(l *ListNode) []int {
	var result []int
	for {
		if l == nil {
			break
		}
		result = append(result, l.Val)
		l = l.Next
	}
	return result
}

func Test_addTwoNumbers(t *testing.T) {
	type args struct {
		l1 *ListNode
		l2 *ListNode
	}
	tests := []struct {
		name string
		args args
		want []int
	}{
		{"0+0", args{
			getNodeList([]int{0}),
			getNodeList([]int{0})},
			[]int{0}},
		{"1", args{
			getNodeList([]int{2, 4, 3}),
			getNodeList([]int{5, 6, 4})},
			[]int{7, 0, 8}},
		{"long", args{
			getNodeList([]int{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}),
			getNodeList([]int{5, 6, 4})},
			[]int{6, 6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
		{"a>b,add", args{
			getNodeList([]int{9, 9, 9, 9, 9, 9, 9}),
			getNodeList([]int{9, 9, 9, 9})},
			[]int{8, 9, 9, 9, 0, 0, 0, 1}},
		{"a<b,add", args{
			getNodeList([]int{2, 4, 9}),
			getNodeList([]int{5, 6, 4, 9})},
			[]int{7, 0, 4, 0, 1}},
		{"a=b,add", args{
			getNodeList([]int{5}),
			getNodeList([]int{5})},
			[]int{0, 1}},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := getNums(addTwoNumbers(tt.args.l1, tt.args.l2))
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("%v addTwoNumbers() = %v, want %v", tt.name, got, tt.want)
			}
		})
	}
}
